<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程操作日志</title>
    <#include "/pubHeadStyle.html">
</head>
<body>

<div style="position: relative;height: 100%;">
    <div class="tablesize roles" style="position: absolute;top:0;right:0px;bottom: 0;left: 0px; padding: 10px">
        <table id="processInstanceLogTable" lay-filter="processInstanceLogTable"></table>
    </div>
</div>

<script type="text/html" id="headerToolsBar" >
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">
                <i class="layui-icon layui-icon-delete"></i>
                <span>删除</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
        </div>
        <form class="layui-form" action="" lay-filter="instanceQueryForm" style="margin-top:10px">
            <input type="hidden" name="runId" id="RunId" class="layui-input filter-value" value="${runId}"/>
            <div class="table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">流程标题</label>
                    <input type="text" name="Q_processSubject_SL" id="processSubject" class="layui-input filter-value"
                           placeholder="流程标题"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">用户名称</label>
                    <input type="text" name="Q_userName_SL" id="userName" class="layui-input filter-value"
                           placeholder="用户名称"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">操作类型</label>
                    <select name="Q_operatorType_SN" id="operatorType" class="layui-input filter-value">
                        <option value="">--全部--</option>
                        <option value="0">启动流程</option>
                        <option value="1">交办</option>
                        <option value="2">撤销</option>
                        <option value="3">删除流程实例</option>
                        <option value="4">同意(投票)</option>
                        <option value="5">反对(投票)</option>
                        <option value="6">弃权(投票)</option>
                        <option value="7">补签</option>
                        <option value="8">驳回</option>
                        <option value="9">驳回到发起人</option>
                        <option value="10">删除任务</option>
                        <option value="11">代理任务</option>
                        <option value="13">锁定任务</option>
                        <option value="14">任务解锁</option>
                        <option value="15">添加意见</option>
                        <option value="16">任务指派</option>
                        <option value="17">设定所有人</option>
                        <option value="18">结束任务</option>
                        <option value="20">收回任务</option>
                        <option value="21">结束流程实例</option>
                        <option value="22">保存流程草稿</option>
                        <option value="23">删除流程草稿</option>
                        <option value="24">办结转发</option>
                        <option value="25">追回</option>
                        <option value="26">任务交接</option>
                    </select>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">操作时间</label>
                    <input type="text" name="Q_createTime_DL" id="createTime" class="layui-input filter-value"
                           placeholder="开始时间"/>
                    <span style="float:left;margin-left:46px">至</span>
                    <input type="text" name="Q_endCreateTime_DG" id="endCreateTime" class="layui-input filter-value"
                           placeholder="结束时间"
                           style="margin-left:60px"/>
                </div>
            </div>
        </form>
    </div>
</script>


<script type="text/html" id="procLogBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a>
</script>

<script>

    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','table', 'layer', 'util', 'commons', 'setter', 'totalFilter', 'laydate', 'common','admin'], function () {
        var table = layui.table;
        var layer = layui.layer;
        var util = layui.util;
        var laydate = layui.laydate;
        var $ = layui.$;
        var setter = layui.setter;
        var commons = layui.commons;
        var common = layui.common;
        var totalFilter = layui.totalFilter;
        var admin = layui.admin;

        var dataPrivacyLevel;
        var privacyLevel = ${privacyLevel};

        var tableH = commons.tabHeight();

        var runId = '${runId}';

        //第一个实例
        table.render({
            elem: '#processInstanceLogTable'
            , cellMinWidth: 70
            , title: '流程操作日志'
            , height: tableH
            , url: serverPath.workflowPath + setter.workflowLinkPath + 'bpmRunLog/list'
            , where: {runId: runId}
            , method: 'post'
            ,defaultToolbar: ['filter', 'print']
            , toolbar: '#headerToolsBar'
            ,autoSort: false
            , page: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {
                    field: 'processSubject',
                    title: '流程标题',
                    sort: true,
                    minWidth: 330,
                    align: 'center',
                    templet: function (d){
                        if(d.operatorType == 3 || d.operatorType == 23) {
                            return '<div>'+d.processSubject+'</div>';
                        }else{
                            return '<div lay-event="get" style="cursor: pointer;color:#1E9FFF ;" >'+d.processSubject+'</div>';
                        }
                    }
                }
                , {field: 'userName', title: '用户名称', sort: true,align: 'center'}
                , {
                    field: 'createTime', title: '操作时间',minWidth: 200, sort: true, align: 'center', templet: function (d) {
                        if (d.createTime == undefined) {
                            return "";
                        } else {
                            return util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                }
                , {
                    field: 'operatorType', title: '操作类型', sort: true, align: 'center', templet: function (d) {
                        if (d.operatorType == undefined) {
                            return "";
                        }
                        if (d.operatorType == 0) {
                            return '<span style="color: #15cc08;">启动流程</span>';
                        }
                        if (d.operatorType == 1) {
                            return '<span style="color: #15cc08;">交办</span>';
                        }
                        if (d.operatorType == 2) {
                            return '<span style="color: #cc0c00;">撤销</span>';
                        }
                        if (d.operatorType == 3) {
                            return '<span style="color: #cc0c00;">删除流程实例</span>';
                        }
                        if (d.operatorType == 4) {
                            return '<span style="color: #15cc08;">同意(投票)</span>';
                        }
                        if (d.operatorType == 5) {
                            return '<span style="color: #cc0c00;">反对(投票)</span>';
                        }
                        if (d.operatorType == 6) {
                            return '<span style="color: #15cc08;">弃权(投票)</span>';
                        }
                        if (d.operatorType == 7) {
                            return '<span style="color: #15cc08;">补签</span>';
                        }
                        if (d.operatorType == 8) {
                            return '<span style="color: #cc0c00;">驳回</span>';
                        }
                        if (d.operatorType == 9) {
                            return '<span style="color: #cc0c00;">驳回到发起人</span>';
                        }
                        if (d.operatorType == 10) {
                            return '<span style="color: #cc0c00;">删除任务</span>';
                        }
                        if (d.operatorType == 11) {
                            return '<span style="color: #15cc08;">代理任务</span>';
                        }
                        if (d.operatorType == 13) {
                            return '<span style="color: #15cc08;">锁定任务</span>';
                        }
                        if (d.operatorType == 14) {
                            return '<span style="color: #15cc08;">任务解锁</span>';
                        }
                        if (d.operatorType == 15) {
                            return '<span style="color: #15cc08;">添加意见</span>';
                        }
                        if (d.operatorType == 16) {
                            return '<span style="color: #15cc08;">任务指派</span>';
                        }
                        if (d.operatorType == 17) {
                            return '<span style="color: #15cc08;">设定所有人</span>';
                        }
                        if (d.operatorType == 18) {
                            return '<span style="color: #15cc08;">结束任务</span>';
                        }
                        if (d.operatorType == 19) {
                            return '<span style="color: #15cc08;">更改执行路径</span>';
                        }
                        if (d.operatorType == 20) {
                            return '<span style="color: #15cc08;">收回任务</span>';
                        }
                        if (d.operatorType == 21) {
                            return '<span style="color: #15cc08;">结束流程实例</span>';
                        }
                        if (d.operatorType == 22) {
                            return '<span style="color: #15cc08;">保存流程草稿</span>';
                        }
                        if (d.operatorType == 23) {
                            return '<span style="color: #cc0c00;">删除流程草稿</span>';
                        }
                        if (d.operatorType == 24) {
                            return '<span style="color: #15cc08;">办结转发</span>';
                        }
                        if (d.operatorType == 25) {
                            return '<span style="color: #cc0c00;">追回</span>';
                        }
                        if (d.operatorType == 26) {
                            return '<span style="color: #15cc08;">任务交接</span>';
                        }
                    }
                }
                , {field: 'memo', title: '备注', sort: true,align: 'center'}
                , {title: '管理', toolbar: '#procLogBar', align: 'center'}
            ]]
            ,done:function () {
                table.resize('processInstanceLogTable');
                commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
            }
        });
        totalFilter.init('processInstanceLogTable');

        table.on('toolbar(processInstanceLogTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("processInstanceLogTable", "instanceQueryForm", {where: {}}, false);
                    break;
                case 'del':
                    if (data.length === 0) {
                        layer.msg('请先选择一行数据！');
                    } else {
                        var seleIds = [];
                        for (var i = 0; i < data.length; i++) {
                            seleIds.push(data[i].id);
                        }
                        var s = seleIds.join(",");
                        layer.confirm('确定删除当前数据吗？',{title: '删除确认'}, function (index) {
                            layer.close(index);
                            $.ajax({
                                url: serverPath.workflowPath + setter.workflowLinkPath + 'bpmRunLog/del?id=' + s,
                                type: 'GET',
                                dataType: 'json',
                                success: function (result) {
                                    if(result.code == 0){
                                        layer.alert(result.msg, function (index2) {
                                            layer.close(index2);
                                            //执行重载
                                            table.reload('processInstanceLogTable');
                                            totalFilter.init('processInstanceLogTable');
                                        });
                                    }else {
                                        layer.alert(data.msg);
                                    }

                                },
                                error: function (XMLHttpRequest) {
                                    layer.alert("请求失败！" + XMLHttpRequest.status);
                                }
                            });
                        })
                    }
                    break;
                case 'reset':
                    common.tableConditionRender("processInstanceLogTable", "instanceQueryForm", {where: {}}, true);
                    break;
            }
        });
        //监听行工具事件
        table.on('tool(processInstanceLogTable)', function (obj) {
            var data = obj.data;
            var runId = data.runId;
            $.ajax({
                url: serverPath.workflowPath + setter.workflowLinkPath + "processRun/getPrivacyLevelByRunId",
                data: {runId: runId},
                type: "post",
                dataType: 'json',
                success: function (result) {
                    dataPrivacyLevel = result;
                    if (privacyLevel < dataPrivacyLevel) {
                        layer.msg('密级不足,无法执行该操作', {icon: 5});
                    } else {
                        switch (obj.event) {
                            case 'del':
                                layer.confirm("确定删除当前数据吗？", {title: '删除确认'}, function (index) {
                                    layer.close(index);
                                    $.ajax({
                                        url: serverPath.workflowPath + setter.workflowLinkPath + "bpmRunLog/del?id=" + data.id,
                                        type: 'GET',
                                        dataType: 'json',
                                        data: {cascade: false},
                                        success: function (result) {
                                            if (result.code == 0) {
                                                layer.alert(result.msg, function (index2) {
                                                    layer.close(index2);
                                                    //执行重载
                                                    table.reload('processInstanceLogTable', {
                                                        page: {curr: 1, limit: 10}
                                                    });
                                                    totalFilter.init('processInstanceLogTable');
                                                });
                                            } else {
                                                layer.alert(data.msg);
                                            }
                                        },
                                        error: function (XMLHttpRequest) {
                                            layer.alert("请求失败！" + XMLHttpRequest.status);
                                        }
                                    });
                                });
                                break;
                            case 'detail':
                                layer.open({
                                    type: 2,
                                    title: "流程明细",
                                    shade: 0.3,
                                    left: 200,
                                    area: ['800px', '400px'],
                                    content: serverPath.workflowPath + setter.workflowLinkPath + 'bpmRunLog/view/get?id=' + data.id
                                });
                                break;
                            case 'get':
                                window.open(serverPath.workflowPath + setter.workflowLinkPath + 'processRun/view/get?runId=' + runId);
                                break;
                        }
                    }
                }
            });
        });

        commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
        window.Initialization = function () {
            commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
        };
        common.tableSort("processInstanceLogTable",{show:window.Initialization});

        if ("${runId != null && runId !='' }"){
            $("#hideLog").hide();
        }else {
            $("#hideLog").show();
        }

    });


</script>
</body>
</html>
